package cn.dansj.service.Impl;

import cn.dansj.entity.ShortLink;
import cn.dansj.repository.ShortLinkRepository;
import cn.dansj.service.ShortLinkService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShortLinkServiceImpl implements ShortLinkService {
    private final ShortLinkRepository shortLinkRepository;

    public ShortLinkServiceImpl(ShortLinkRepository shortLinkRepository) {
        this.shortLinkRepository = shortLinkRepository;
    }

    @Override
    public ShortLink getUrl(String url, int userId) {
        return shortLinkRepository.findByUrlAndUserId(url, userId);
    }

    @Override
    public int countByUserId(int userId) {
        return shortLinkRepository.countAllByUserId(userId);
    }

    @Override
    public void save(ShortLink shortLink) {
        shortLinkRepository.save(shortLink);
    }

    @Override
    public void save(List<ShortLink> shortLinks) {
        shortLinkRepository.saveAll(shortLinks);
    }
}
